<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.rsscollector.model.CatalogFacade" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib prefix="app" uri="/WEB-INF/tlds/app.tld" %>

<cache:cache key="/category.jsp?categoryId=${param['categoryId']}">

<c:set var="categoryItems" value="${app:getItemsForCategory(param['categoryId'])}" scope="page"/>

<table cellpadding="0" cellspacing="10" border="0">
    <tr>
    	<td>
		<c:forEach var="item" items="${categoryItems}" varStatus="status">
            <c:if test="${status.index % 3 == 0}">
                <p><a href="${item.link}"><c:out value="${item.title}" /></a></p>
                <p>${item.descriptionValue}</p>
                <c:if test="${item.group != null && fn:length(item.group.news) > 1}">
                	<p>Related news: 
                	<c:forEach var="relatedNews" items="${item.group.news}">
                		<a href="${relatedNews.link}">${relatedNews.title}</a>|
                	</c:forEach>
                </c:if>
            </c:if>
        </c:forEach>
        </td>
        <td>
        <c:forEach var="item" items="${categoryItems}" varStatus="status">
            <c:if test="${status.index % 3 == 1}">
                <p><a href="${item.link}"><c:out value="${item.title}" /></a></p>
                <p>${item.descriptionValue}</p>
                <c:if test="${item.group != null && fn:length(item.group.news) > 1}">
                	<p>Related news: 
                	<c:forEach var="relatedNews" items="${item.group.news}">
                		<a href="${relatedNews.link}">${relatedNews.title}</a>|
                	</c:forEach>
                </c:if>
            </c:if>
        </c:forEach>
        </td>
        <td>
        <c:forEach var="item" items="${categoryItems}" varStatus="status">
            <c:if test="${status.index % 3 == 2}">
                <p><a href="${item.link}"><c:out value="${item.title}" /></a></p>
                <p>${item.descriptionValue}</p>
                <c:if test="${item.group != null && fn:length(item.group.news) > 1}">
                	<p>Related news: 
                	<c:forEach var="relatedNews" items="${item.group.news}">
                		<a href="${relatedNews.link}">${relatedNews.title}</a>|
                	</c:forEach>
                </c:if>
            </c:if>
        </c:forEach>
        </td>
	</tr>
</table>
</cache:cache>